﻿@using Model.WXshopBuiness;
@using Xproject.Util;
@{
    string Domain = CommonHelper.GetAppSettings("Domin");
    Layout = "~/Views/Shared/_JSlayout.cshtml";
    string productId = ViewBag.productId; string ProductCode = string.Empty; string ProductName = string.Empty;
    if (!string.IsNullOrEmpty(productId))
    {
        ProductCode = ViewBag.ProductCode;
        ProductName = ViewBag.ProductName;
    }
    string now = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
}
@model ProductComments
<link href="@Domain/Content/datetimepicker/css/bootstrap-datetimepicker.min.css" rel="stylesheet" />
<script src="@Domain/Content/datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
<div class="gray-bg">
    <div class="  animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>@ViewBag.Title</h5>
                    </div>
                    <div class="ibox-content">
                        <form class="form-horizontal m-t" id="formProductComment" action="~/WXProduct/EditProductComment" method="post">
                            <div class="form-group">
                                @if (string.IsNullOrEmpty(productId))
                                {
                                    <label class="col-sm-3 control-label">产品code：</label>
                                    <div class="col-sm-8">
                                        <input id="ProductCode" name="ProductCode" class="form-control" type="text" required min="4" value="@(Model != null ? Model.ProductCode : "")">
                                        <span class="help-block m-b-none"><i class="fa fa-info-circle"></i></span>
                                    </div>
                                    if (Model != null)
                                    {
                                        <label class="col-sm-3 control-label">产品名称：</label>
                                        <div class="col-sm-8">
                                            <input id="ProductName" readonly name="ProductName" class="form-control" type="text" min="4" value="@(Model != null ? Model.ProductName : "")">
                                            <span class="help-block m-b-none"><i class="fa fa-info-circle"></i></span>
                                        </div>
                                    }
                                }
                                else
                                {
                                    <input type="hidden" name="ProductID" value="@productId" />
                                    <input type="hidden" name="ProductCode" value="@ProductCode" />
                                    <input type="hidden" name="ProductName" value="@ProductName" />
                                }

                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">用户名：</label>
                                <div class="col-sm-8">
                                    <input id="UserName" name="UserName" class="form-control" type="text" required min="2" placeholder="模拟用户，请设置的像样点" value="@(Model!=null?Model.UserName:"")">
                                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">用户头像：</label>
                                <div class="col-sm-8">
                                    <input id="productComments" name="productComments" class="form-control" type="file">
                                    @if (Model != null)
                                    {
                                        <img id="imgUser" src="@(Model.Domain + Model.UserImgUrl)" style="width:60px;height:60px" />
                                    }
                                    else
                                    {
                                        <img id="imgUser" src="" style="width:60px;height:60px;display:none" />
                                    }

                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">评论内容：</label>
                                <div class="col-sm-8">
                                    <textarea id="Comment" name="Comment" class="form-control" aria-required="true" aria-invalid="false" class="valid"
                                              required>@(Model!=null?Model.Comment : "")</textarea>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">排序：</label>
                                <div class="col-sm-8">
                                    <input id="CommentIndex" name="CommentIndex" class="form-control" type="number" aria-required="true" aria-invalid="false" class="valid" value="@(Model!=null?Model.CommentIndex:1)" required>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">五星数：</label>
                                <div class="col-sm-8">
                                    <input type="number" min="1" max="5" class="form-control" name="CommentTotalStarts" id="CommentTotalStarts" placeholder="5星好评" required value="@(Model!=null?Model.CommentTotalStarts:1)" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">服务星数：</label>
                                <div class="col-sm-8">
                                    <input type="number" min="1" max="5" class="form-control" name="CommentServiceStarts" id="CommentServiceStarts" placeholder="5星好评" required value="@(Model!=null?Model.CommentServiceStarts:1)" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">物流星数：</label>
                                <div class="col-sm-8">
                                    <input type="number" min="1" max="5" class="form-control" name="CommentLogisticStarts" id="CommentLogisticStarts" placeholder="5星好评" required value="@(Model!=null?Model.CommentLogisticStarts:1)" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">包装星数：</label>
                                <div class="col-sm-8">
                                    <input type="number" min="1" max="5" class="form-control" name="CommentPackageStarts" id="CommentPackageStarts" placeholder="5星好评" required value="@(Model!=null?Model.CommentPackageStarts:1)" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">评论时间：</label>
                                <div class="col-sm-8">
                                    <input type="text"  name="CreateTime" id="CreateTime" placeholder="" required value="@(Model!=null?Model.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"):now)" />
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-8 col-sm-offset-3">
                                    <div class="checkbox">
                                        <label>
                                            @if (Model != null)
                                            {
                                                <input type="checkbox" @(Model.Enable == 1 ? "checked" : "") class="checkbox" id="Enable" name="Enable">@("启用")
                                            }
                                            else
                                            {
                                                <input type="checkbox" class="checkbox" id="Enable" name="Enable">@("启用")
                                            }
                                        </label>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-8 col-sm-offset-3">
                                    @if (Model != null)
                                    {
                                        <input type="hidden" name="ID" value="@Model.ID" />
                                    }
                                    <button class="btn btn-primary" type="submit">提交</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 全局js -->

<script type="text/javascript">
    $(document).ready(function () {
        var optionsNew = {
            beforeSubmit: function () {
                //layer.open({ type: 2, time: 2 });
                layer.load(1, { shade: [0.1, '#000'], time: 2000 });
            },
            success: function (data) {
                if (data.Success == true) {
                    layer.alert('编辑成功', { icon: 1, skin: 'layer-ext-moon', time: 2000 });
                } else {
                    layer.alert(data.Data, { icon: 1, skin: 'layer-ext-moon', time: 2000 });
                }
            },
            error: function () {
                alert(JSON.stringify(data));
            },
            type: "post",
            clearForm: false,
            timeout: 100000
        };
        $("#formProductComment").submit(function () {
            $("#formProductComment").ajaxSubmit(optionsNew);// type="button"
            return false;
        });
    });

    $("#productComments").on("change", function () {
        var file = this.files[0];
        if (this.files && file) {
            var reader = new FileReader();
            reader.onload = function (e) {
                $("#imgUser").attr("src", e.target.result);
                $("#imgUser").show();
            }
            reader.readAsDataURL(file);
        }
    });

</script>


<script type="text/javascript">
    $(function () {
        $("#CreateTime").datetimepicker();        
    });
</script>
